package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author lyl
 * @created 2025/10/9 9:03
 * @description
 *
 */
@Slf4j
@RestController
@RequestMapping("/activities")
@SuppressWarnings("all")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result getListByPage(@RequestParam(required = false) Integer channel,
                                @RequestParam(required = false) Integer type,
                                @RequestParam(required = false) Integer status,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("分页查询活动(getListByPage): channel={}, type={}, status={}, page={}, pageSize={}", channel, type, status, page, pageSize);
        PageResult<Activity> pageResult = activityService.getListByPage(channel, type, status, page, pageSize);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result add(@RequestBody Activity activity) {
        log.info("添加活动：activity={}", activity.toString());
        activityService.add(activity);
        return Result.success();
    }

    @LogAnno
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除活动：id={}", id);
        activityService.delete(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable Integer id) {
        log.info("通过id查询活动：id={}", id);
        Activity activity = activityService.getActivityById(id);
        return Result.success(activity);
    }

    @LogAnno
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动：activity={}", activity.toString());
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result getListByType(@PathVariable Integer type) {
        log.info("通过类型查询活动：type={}", type);
        List<Activity> list = activityService.getListByType(type);
        return Result.success(list);
    }
}
